package com.zzxx.www.dao.impl;

import com.zzxx.www.dao.LoginDao;
import com.zzxx.www.domain.Admin;
import com.zzxx.www.domain.User;
import com.zzxx.www.utils.DruidUtil;
import com.zzxx.www.utils.LoginException;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class LoginDaoImpl implements LoginDao {
	private JdbcTemplate template = new JdbcTemplate(DruidUtil.getDataSource());
	@Override
	public Admin login(String usrname) throws LoginException {
		String sql = "select * from admin where loginname = ?";
		try{
			Admin admin = template.queryForObject(sql, new BeanPropertyRowMapper<>(Admin.class), usrname);
			return admin;
		}catch (DataAccessException e){
			throw new LoginException("用户名不存在");
		}
	}
}
